var app = getApp()
const util = require('../../utils/util.js')
 Page({
data: { 
    fostered_catlist: [
    { name:"杰希"},
    { name:"土谦"},
    ],
    unknown_catlist: [
    ],
    dead_catlist: [
    ],
    screenWidth: 0,
    screenHeight: 0,
    imgwidth: 0,
    imgheight: 0,
    navbar: ['在巷居民', '乔迁新居', '外出旅行', '回到喵星'],
    currentTab: 0,
    url: app.globalData.url,
    configurl: app.globalData.configurl,
    cattypes: [],
    catlist: {}
  },
  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
  },

  iconType: [
    'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
  ],

  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },

  //转发跳转页面设置
  onLoad: function (options) {
    if (options.pageId) {
      wx.navigateTo({
        url: '/pages/cats/' + options.pageId + '/' + options.pageId,
      })
    }
    
  },

  onLoad: function(){
    var _this = this;
    util.getCatConfig(app.globalData.configurl + "config/cattypes.json").then( res => {
      _this.setData({
        cattypes: res,
        catlist: app.globalData.cats
      })
      // console.log(_this.data.catlist);
    })
  },

  //转发此页面的设置
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      path: 'pages/index/index',  // 路径，传递参数到指定页面。
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },

  // 转发到朋友圈
  onShareTimeline: function (res) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      path: 'pages/index/index',  // 路径，传递参数到指定页面。
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },

  // 搜索栏输入名字后页面跳转
  bindconfirmT: function (e) {
    console.log(e.detail.value);
    var _this = this;
    if (e.detail.value) {
      wx.navigateTo({
        url: "/pages/index/cats/cats?cattype=all&state=" + _this.data.currentTab + "&search=" + e.detail.value,
      })
    }
  },
  copyTBL: function (e) {
    var self = this;
    wx.setClipboardData({
      data: '古北二喵',//需要复制的内容
      success: function (res) {
        // self.setData({copyTip:true}),

      }
    })
  },

  gotocatdetailed: function(e) {
    wx.navigateTo({
      url: '/pages/index/catdetailed/catdetailed?catinfo=' + JSON.stringify(e.currentTarget.dataset.item)
    })
  },

})

